/**
 * Copyright 2019 Inc.
 **/
package com.myz.service.feign.config;

import feign.Response;
import feign.codec.ErrorDecoder;
import lombok.extern.slf4j.Slf4j;

/**
 * 全局定义error处理
 *
 * @author maoyz0621 on 19-12-17
 * @version: v1.0
 */
@Slf4j
public class UserErrorDecoder implements ErrorDecoder {

    @Override
    public Exception decode(String methodKey, Response response) {
        log.error("methodKey = {}, response = {}", methodKey, response);
        int status = response.status();
        String reason = response.reason();
        System.out.println();
        Exception exception = null;
        // try {
        //     // 获取原始的返回内容
        //     String json = Util.toString(response.body().asReader());
        //     exception = new RuntimeException(json);
        //     // 将返回内容反序列化为Result，这里应根据自身项目作修改
        //     Result result = JsonMapper.nonEmptyMapper().fromJson(json, Result.class);
        //     // 业务异常抛出简单的 RuntimeException，保留原来错误信息
        //     if (!result.isSuccess()) {
        //         exception = new RuntimeException(result.getMessage());
        //     }
        // } catch (IOException ex) {
        //     logger.error(ex.getMessage(), ex);
        // }
        return exception;
    }
}